import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TaskVO, TaskForm, TaskQuery } from '@/api/task/task/types';

/**
 * 查询任务列表
 * @param query
 * @returns {*}
 */

export const pageTask = (query?: TaskQuery): AxiosPromise<TaskVO[]> => {
  return request({
    url: '/oa/task/page',
    method: 'get',
    params: query
  });
};

export const pageSubTask = (query?: TaskQuery): AxiosPromise<TaskVO[]> => {
  return request({
    url: '/oa/task/pageSubTask',
    method: 'get',
    params: query
  });
};

/**
 * 查询任务详细
 * @param taskId
 */
export const getTask = (taskId: string | number): AxiosPromise<TaskVO> => {
  return request({
    url: '/oa/task/' + taskId,
    method: 'get'
  });
};

/**
 * 新增任务
 * @param data
 */
export const addTask = (data: TaskForm) => {
  return request({
    url: '/oa/task/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改任务
 * @param data
 */
export const updateTask = (data: TaskForm) => {
  return request({
    url: '/oa/task/edit',
    method: 'put',
    data: data
  });
};

export const updateObjectionTask = (data: TaskForm) => {
  return request({
    url: '/oa/task/updateObjectionTask',
    method: 'put',
    data: data
  });
};

/**
 * 删除任务
 * @param taskId
 */
export const delTask = (taskId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/task/' + taskId,
    method: 'delete'
  });
};

export const objectionTask = (taskId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/task/objection/' + taskId,
    method: 'post'
  });
};

export const discardTask = (taskId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/task/discard/' + taskId,
    method: 'post'
  });
};

export const returnTask = (taskId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/task/returnTask/' + taskId,
    method: 'post'
  });
};

/**
 * 任务状态流转
 * @param data
 */
export const turn = (data: TaskForm) => {
  return request({
    url: '/oa/task/turn',
    method: 'post',
    data: data
  });
};

/**
 * 任务状态流转
 * @param processInstanceId
 */
export const getTaskInfo = (processInstanceId: string) => {
  return request({
    url: '/oa/task/info',
    method: 'get',
    params: { processInstanceId: processInstanceId }
  });
};

/**
 * 任务状态流转
 * @param processInstanceId
 */
export const downLoadRestockingTemplate = () => {
  return request({
    url: '/oa/task/downLoadRestockingTemplate',
    method: 'post',
    params: {}
  });
};
